cmake_minimum_required(VERSION 3.5)

project(NjuPro VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt6 REQUIRED COMPONENTS Multimedia)

set(TS_FILES NjuPro_zh_CN.ts)

set(PROJECT_SOURCES
        head.h
        Cargo/Cargo.cc
        Cargo/Cargo.h
        Cargo/Cargo_Manager.cc
        Cargo/Cargo_Manager.h
        Cargo/Color.cc
        Cargo/Color.h
        Cargo/Shape.cc
        Cargo/Shape.h
        Facility/Hub.cc
        Facility/Hub.h
        Facility/Facility.cc
        Facility/Facility.h
        Facility/Facility_Manager.cc
        Facility/Facility_Manager.h
        Grid/Gate.h
        Grid/Grid.cc
        Grid/Grid.h
        main.cpp
        mainwindow.cpp
        mainwindow.h
        utils/My_Mouse.cc
        utils/My_Mouse.h
        GameLogic/GameLogic.cc
        GameLogic/GameLogic.h
        mainwindow.ui
        ${TS_FILES}
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(NjuPro
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        resource.qrc
        Facility/Facility_Define.h Facility/Facility_Define.cpp
        Facility/Hub_Define.h Facility/Hub_Define.cpp
        head_Q.h
        utils/mypushbutton.h utils/mypushbutton.cpp
        utils/Object_qt.h utils/Object_qt.cpp
        utils/scene_qt.h utils/scene_qt.cpp
        PaintSystem/paint_system.h PaintSystem/paint_system.cpp
        Scene/game_scene.h Scene/game_scene.cpp
        Scene/help_scene.h Scene/help_scene.cpp
        Facility/Belt/base_belt.h Facility/Belt/base_belt.cpp
        Facility/Belt/belt_path.h Facility/Belt/belt_path.cpp
        utils/View_qt.h utils/View_qt.cpp
        utils/data_manager.h utils/data_manager.cpp
        Scene/shop_scene.h Scene/shop_scene.cpp
        Scene/Scene.h
        Facility/Miner/miner.h Facility/Miner/miner.cpp
        Facility/FacilityIconButton/facilityiconbutton.h Facility/FacilityIconButton/facilityiconbutton.cpp
        Facility/FacilityIconButton/facilitybutton.h Facility/FacilityIconButton/facilitybutton.cpp

        Grid/map_data_manager.h Grid/map_data_manager.cpp
        Grid/mapgenerator.h Grid/mapgenerator.cpp
        Facility/Belt/belt_define.h Facility/Belt/belt_define.cpp
        Facility/Cutter/cutter_define.h Facility/Cutter/cutter_define.cpp
        Facility/Cutter/cutter.h Facility/Cutter/cutter.cpp
        Facility/Miner/miner_define.h Facility/Miner/miner_define.cpp
        Facility/trash.h Facility/trash.cpp
        Facility/rotator.h Facility/rotator.cpp
        Facility/balancer.h Facility/balancer.cpp

    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET NjuPro APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation

    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
    if(ANDROID)
        add_library(NjuPro SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(NjuPro
            ${PROJECT_SOURCES}
        )
    endif()

    qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

target_link_libraries(NjuPro PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(NjuPro PRIVATE Qt6::Multimedia)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.NjuPro)
endif()
set_target_properties(NjuPro PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS NjuPro
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(NjuPro)
endif()
